package com.bwie.redkids;

import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;

public class LoginActivity extends Activity implements OnClickListener {

	private Button detail_back;
	private EditText ed_yuni_user;
	private EditText ed_yuni_pwd;
	private Button but_login;
	private ImageView qq_login;
	private ImageView sina_login;
	private ImageView weixin_login;
	private UMShareAPI mShareAPI;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_login);
		initView();
	}

	private void initView() {
		detail_back = (Button) findViewById(R.id.detail_back);
		ed_yuni_user = (EditText) findViewById(R.id.ed_yuni_user);
		ed_yuni_pwd = (EditText) findViewById(R.id.ed_yuni_pwd);
		but_login = (Button) findViewById(R.id.but_login);
		qq_login = (ImageView) findViewById(R.id.qq_login);
		sina_login = (ImageView) findViewById(R.id.sina_login);
		weixin_login = (ImageView) findViewById(R.id.weixin_login);

		detail_back.setOnClickListener(this);
		but_login.setOnClickListener(this);
		qq_login.setOnClickListener(this);
		sina_login.setOnClickListener(this);
		weixin_login.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.detail_back:
			LoginActivity.this.finish();
			break;
		case R.id.but_login:

			break;
		case R.id.qq_login:

			mShareAPI = UMShareAPI.get(this);
			SHARE_MEDIA platform = SHARE_MEDIA.QQ;
			mShareAPI.doOauthVerify(this, platform, umAuthListener);
			// get user info
			mShareAPI.getPlatformInfo(this, platform, umAuthListener);

			break;
		case R.id.sina_login:

			break;
		case R.id.weixin_login:

			break;
		default:
			break;
		}
	}

	UMAuthListener umAuthListener = new UMAuthListener() {
		@Override
		public void onComplete(SHARE_MEDIA platform, int action,
				Map<String, String> data) {
			Toast.makeText(getApplicationContext(), "Authorize succeed",
					Toast.LENGTH_SHORT).show();
		}

		@Override
		public void onError(SHARE_MEDIA platform, int action, Throwable t) {
			Toast.makeText(getApplicationContext(), "Authorize fail",
					Toast.LENGTH_SHORT).show();
		}

		@Override
		public void onCancel(SHARE_MEDIA platform, int action) {
			Toast.makeText(getApplicationContext(), "Authorize cancel",
					Toast.LENGTH_SHORT).show();
		}
	};

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		mShareAPI.onActivityResult(requestCode, resultCode, data);
	}

}
